import { inject, type InjectionKey } from "vue";

type ToastHandler = (
  message: string,
  options?: { title?: string; duration?: number }
) => void;
export const ToastInjectKey = Symbol() as InjectionKey<{
  info: ToastHandler;
  success: ToastHandler;
  warning: ToastHandler;
  error: ToastHandler;
}>;

export function useToast() {
  const toast = inject(ToastInjectKey);
  if (!toast) {
    throw new Error("useToast must be used within a ToastProvider");
  }
  return toast;
}
